package com.dongdongshop.service.impl;


import com.dongdongshop.mapper.TbSellerMapper;
import com.dongdongshop.page.PageResult;
import com.dongdongshop.pojo.TbSeller;
import com.dongdongshop.service.TbSellerService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@DubboService
public class TbSellerServiceImpl implements TbSellerService {
    @Autowired
    private TbSellerMapper sellerMapper;

    @Override
    public TbSeller selectSellerById(String sellerId) {
        return sellerMapper.selectByPrimaryKey(sellerId);
    }

    @Override
    public PageResult<TbSeller> selectSeller(String name,String sName,Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<TbSeller> listSeller = sellerMapper.selectByStuAndLikeName(name,sName);
        PageInfo<TbSeller> i = new PageInfo<>(listSeller);
        return new PageResult(i.getPageNum(),i.getPageSize(),i.getTotal(),i.getPages(),i.getList());
    }


    @Override
    public void updateById(TbSeller seller) {
        sellerMapper.updateByPrimaryKeySelective(seller);
    }

    @Override
    public PageResult<TbSeller> selectSeller2(String name, String sName, Integer pageNum, Integer pageSize, String staus) {
        PageHelper.startPage(pageNum,pageSize);
        List<TbSeller> listSeller = sellerMapper.selectByStuAndLikeName2(name,sName,staus);
        PageInfo<TbSeller> i = new PageInfo<>(listSeller);
        return new PageResult(i.getPageNum(),i.getPageSize(),i.getTotal(),i.getPages(),i.getList());
    }

    @Override
    public void addSeller(TbSeller tbSeller) {
        sellerMapper.insertSelective(tbSeller);
    }

    @Override
    public String selectSellerNameBySellerId(String sellerId) {
        return sellerMapper.selectSellerNameBySellerId(sellerId);
    }
}
